﻿@using EIP.Common.Entities.Dtos
@using EIP.System.Models.Enums
@using EIP.Web.AdminLTE.DataUsers.Helpers

@{
    ViewBag.Title = "省市区县信息编辑";
    Layout = "~/Views/Shared/_LayoutPageBaseEdit.cshtml";
}
@model EIP.System.Models.Entities.SystemDistrict
<div class="box-body">
    <div class="col-md-12">

        <div class="form-group">
            <label class="col-sm-2 control-label m">名称</label>
            <div class="col-sm-10">
                <input type="text" name="Name" id="Name" value="@Model.Name" data-pure-clear-button class="form-control" placeholder="名称">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">代码</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.DistrictId" data-pure-clear-button id="DistrictId" name="DistrictId" placeholder="代码">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">简称</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.ShortName" data-pure-clear-button id="ShortName" name="ShortName" placeholder="简称">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">等级</label>
            <div class="col-sm-10">
                @Html.DropDownListEnum(new DropDownListEnumInput
                {
                    EnumType = (typeof(EnumDistrictLevelType)),
                    Name = "LevelType",
                    HtmlAttributes = "class='form-control' style='width: 100%;'",
                    SelectedVal = @Model.LevelType
                })
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">城市代码</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.CityCode" data-pure-clear-button id="CityCode" name="CityCode" placeholder="城市代码">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">邮编</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.ZipCode" data-pure-clear-button id="ZipCode" name="ZipCode" placeholder="邮编">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">经度</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.Lng" data-pure-clear-button id="Lng" name="Lng" placeholder="经度">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">纬度</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.Lat" data-pure-clear-button id="Lat" name="Lat" placeholder="经度">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">拼音</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" value="@Model.PinYin" data-pure-clear-button id="PinYin" name="PinYin" placeholder="代码">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">选项</label>
            <div class="col-sm-10">

                <label>
                    @Html.CheckBoxHtmlString(new CheckBoxInput
                    {
                        Name = "IsFreeze",
                        Title = "冻结",
                        IsCheck = @Model.IsFreeze
                    })
                </label>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label m">排序号</label>
            <div class="col-sm-10">
                <input type="text" value="@Model.OrderNo" name="orderNo" class="form-control" data-pure-clear-button placeholder="排序号">
            </div>
        </div>
    </div>
</div>
@Html.HiddenFor(f => @Model.ParentId)
<script>
    var form = null;
    $(function () {
        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });
        //Red color scheme for iCheck
        $('input[type="checkbox"].minimal-red, input[type="radio"].minimal-red').iCheck({
            checkboxClass: 'icheckbox_minimal-red',
            radioClass: 'iradio_minimal-red'
        });
        //Flat red color scheme for iCheck
        $('input[type="checkbox"].flat-red, input[type="radio"].flat-red').iCheck({
            checkboxClass: 'icheckbox_flat-green',
            radioClass: 'iradio_flat-green'
        });
        $.each($("input:text, input:password, " +
                "input[type='email'], input[type='url'], input[type='search'], input[type='tel'], input[type='number'], " +
                "input[type='datetime'],textarea", $("#editform")),
            function (index, element) {
                var $element = $(element);
                if (($element.attr("data-pure-clear-button") == undefined || $element.attr("data-pure-clear-button") === 'false') && !$element.hasClass("has-pure-clear-button")) {
                    return;
                }
                $element.pureClearButton("create");
            });

        ValidformNeed();

        initForm();
    });

    function initForm() {
        //初始化控件
        form = $("#editform").form();
        //数据校验
        $("#editform").formValidation({
            message: '请输入有效值',
            trigger: 'blur',
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '请输入姓名'
                        }
                    }
                },
                code: {
                    validators: {
                        notEmpty: {
                            message: '请输入代码'
                        }
                    }
                }
            }
        }).on('success.form.fv', function (e) {
            var data = form.getFormSimpleData();
            data["ParentId"] = data["parentName"] !== "" ? data["ParentId"] : "";
            UtilAjaxPostWait("/System/District/SaveDistrict", form.getFormSimpleData(), function () {
                if (DialogAjaxResult(data)) {
                    loadTreeAndGrid();
                    //关闭
                    dialog.close();
                }
            });
            return false;
        });
    }

</script>
